<template>
    <div class="flex flex-col flex-1 p-2">
        <!-- <div class="flex justify-between">
            <div class="flex-1"></div>
            <div>
                <el-button type="primary" @click="openDialog">新增</el-button>
            </div>
        </div> -->
        <CustomTable class="mt-2" :data="tableData" :total="tableTotal" v-model:page-size="pageSize" @pageSize="getList"
            v-model:currentPage="pageNum" @currentPage="getList">
            <el-table-column type="index" width="60" label="序号" />
            <el-table-column prop="name" label="店铺名称" />
            <el-table-column prop="storeDesc" label="描述" />
            <el-table-column prop="storeImg" label="店铺图片">
                <template  #default="{row}">
                    <el-image style="width: 100px; height: 100px" :src="row.storeImg" fit="cover" />
                </template>
            </el-table-column>
        </CustomTable>
    </div>
    <CustomDialog v-model:show="addDialog" title="新增店铺" width="600px" @cancel="cancelDialog" @confirm="submitForm">
        <el-form ref="formRef" :model="shopForm" label-width="auto">
            <el-form-item label="店铺名称" prop="name">
                <el-input v-model="shopForm.name"></el-input>
            </el-form-item>
            <el-form-item label="店铺图片" prop="storeImg">
                <SingleUpload v-model="shopForm.storeImg"></SingleUpload>
            </el-form-item>
            <el-form-item label="店铺描述" prop="storeDesc"><el-input
                    v-model="shopForm.storeDesc"></el-input></el-form-item>
        </el-form>
    </CustomDialog>
</template>

<script setup lang="ts">
import CustomTable from '@/components/CustomTable.vue'
import { onMounted, reactive, ref } from 'vue'
import { addStore, getStoreList } from '@/apis/movie'
import CustomDialog from '@/components/CustomDialog.vue'
import SingleUpload from '@/components/SingleUpload.vue'
const tableData = ref([])
const tableTotal = ref(0)
const pageSize = ref(10)
const pageNum = ref(1)

const getList = async () => {
    const res = await getStoreList({
        pageNum: pageNum.value,
        pageSize: pageSize.value
    })
    console.log(res)
    tableData.value = res.list
    tableTotal.value = res.total
}
const addDialog = ref()
const openDialog = () => {
    addDialog.value = true
}
const cancelDialog = () => {
    addDialog.value = false
}
const submitForm = async () => {
    await addStore(shopForm)
    addDialog.value = false
    getList()
}

const shopForm = reactive({
    name: "",
    storeDesc: "",
    storeImg: ""
})
onMounted(() => {
    getList()
})
</script>

<style scoped></style>
